package org.domain.sample.session;

import java.util.ArrayList;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.onetomany.A;
import model.onetomany.B;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;

import test.TestOneToMany;


@Scope(ScopeType.CONVERSATION)
@Name("sampleAction2")
public class SampleAction2
{
    @Logger private Log log;

    @In StatusMessages statusMessages;
    
//	@PersistenceContext
	@In EntityManager entityManager;
    public void say()
    {
        // implement your business logic here
        log.info("sampleAction2.say() action called");
        
        
        
       add();
        
        
        
        
        
        
        
        
        
        
        
        
//	TestOneToMany testOneToMany = new TestOneToMany(entityManager);
//		 testOneToMany.add();
//		
//		 A a = testOneToMany.getA(1);
//		 System.out.println(a.getAName());
//		 statusMessages.add(a.getAName());
//
//		testOneToMany.addA();
        
        statusMessages.add("say");
    }

    // add additional action methods

    
	public void add() {
		A a = new A("a1");
		B b1 = new B("b1");
		B b2 = new B("b2");
		ArrayList<B> list = new ArrayList<B>();
//		list.add(b1);
//		list.add(b2);
//		a.setBs(list);
		a.setBs(list);
		a.addB(b1);
		a.addB(b2);
		entityManager.persist(a);
	}
}
